package io.zerows.epoch.bootplus.exploit.unit.testing;

import io.vertx.core.json.JsonObject;
import io.zerows.cortex.extension.HExtension;
import io.zerows.epoch.basicore.MDConnect;
import io.zerows.epoch.constant.KName;
import io.zerows.epoch.database.jooq.operation.UxJoin;
import io.zerows.epoch.testsuite.JooqBase;
import io.zerows.platform.metadata.Kv;
import io.zerows.program.Ux;
import io.zerows.support.Ut;

import java.util.Objects;

/**
 * @author lang : 2024-10-25
 */
public abstract class ExtensionBase extends JooqBase {
    static {
        HExtension.initialize();
    }

    protected String inId(final String filename) {
        final JsonObject inFile = this.ioJObject(filename + ".json");
        return Ut.valueString(inFile, KName.ID);
    }

    protected JsonObject inData(final String filename) {
        final JsonObject inFile = this.ioJObject(filename + ".json");
        return Ut.valueJObject(inFile, "params");
    }

    protected UxJoin inJoin(final String filename) {
        final JsonObject config = this.ioJObject(filename + "-join.json");
        // 主表子表
        final MDConnect active = HExtension.connect(Ut.valueString(config, KName.ACTIVE));
        Objects.requireNonNull(active);
        final MDConnect standBy = HExtension.connect(Ut.valueString(config, "standby"));
        Objects.requireNonNull(standBy);
        // 连接点
        final Kv<String, String> kvJoin = Kv.create(
            Ut.valueString(config, "active.field"),
            Ut.valueString(config, "standby.field")
        );
        // 匿名
        return Ux.Join.bridge(active, standBy, kvJoin, Ut.valueJObject(config, KName.ALIAS));
    }
}
